package com.atguigu.spzx.controller;


import com.atguigu.spzx.constant.CacheConstant;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.service.SysRoleService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/system/sysRole")
@Tag(name = "角色模块")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping(value = "/findAllRoles/{id}")
    public Result<Map<String, Object>> findAllRoles(@PathVariable(value = "id") Long id) {
        Map<String, Object> map = sysRoleService.findAllRoles(id);
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }


    @PostMapping("/findPage/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询")
    public Result<PageInfo<SysRole>> findPage(@RequestBody SysRoleDto sysRoleDto,
                                              @PathVariable(value = "pageNum") Integer pageNum,
                                              @PathVariable(value = "pageSize") Integer pageSize) {


        PageInfo<SysRole> pageInfo = sysRoleService.findPage(sysRoleDto, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);


    }

    @PostMapping("/saveRole")
    @Operation(summary = "添加")
    public Result saveRole(@RequestBody SysRole sysRole) {
        sysRoleService.saveRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/updateRole")
    @Operation(summary = "修改")
    public Result updateRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/removeById/{id}")
    @Operation(summary = "修改")
    public Result removeById(@PathVariable Long id) {
        sysRoleService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
